Skip to content

Start HttpCacheManager without its local server (startServer: false) - #20

Merged
Colton127 merged 5 commits into
mainfrom
claude/serverless-init-5aa25e
Nov 6, 2026
Merged

Colton127 merged 5 commits into
mainfrom
claude/serverless-init-5aa25e

Conversation

@Colton127

Copy link
Copy Markdown
Owner

Adds HttpCacheManager.init(startServer: false), which starts the manager without its local cache server, for consumers that read streams directly through createStream and HttpCacheStream.request instead of over HTTP. No socket is bound, so the manager starts where binding is refused, such as a macOS App Sandbox without the com.apple.security.network.server entitlement.

Changes

  • init takes startServer (default true, so existing users are unaffected). With false:
    • Downloading and caching work as usual.
    • port is ignored.
    • ensureActive() does nothing.
    • dispose() works.
  • getCacheUrl and HttpCacheStream.cacheUrl throw a new CacheServerUnavailableException when there's no server. Check HttpCacheManager.hasServer or HttpCacheStream.hasCacheUrl before asking.
  • init clears its pending future only after the future is stored. Without a server and with cacheDir or config given, the init closure has no await. It would then clear _initFuture before the assignment, so a stale future kept handing out a disposed manager.
  • README section, CHANGELOG entry and version bump to 0.3.0.

Tests

  • test/e2e/serverless_test.dart (9 tests) covers:
    • serverless init;
    • streaming and caching a file with no server;
    • ensureActive();
    • dispose and init again;
    • the cache URL errors.
  • The full suite passes (145 tests), and dart analyze lib test is clean.
  • ReliefMix's audio tests (1,030) pass against this branch with startServer: false.

Why

ReliefMix now plays every stream through SoLoud, straight from the manager's streams, so it no longer uses the loopback server. Because init always bound that server, Mac App Store builds never started the manager and never cached a streamed sound.

HttpCacheStream.cacheUrl fell back to the source URL when the manager had
no server, so a player handed it would silently bypass the cache. It now
throws CacheServerUnavailableException, as getCacheUrl does, and
HttpCacheStream.hasCacheUrl / HttpCacheManager.hasServer let callers check
first. Document that ensureActive() is a no-op and port is ignored without
a server.
Without a server and with a cacheDir or config given, init's closure has no
await, so its finally block cleared _initFuture before the ??= stored it.
The completed future stayed behind, and the next init after dispose handed
back the disposed manager.
@Colton127
Colton127 merged commit fca8da3 into main Nov 6, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant